<template>
	<view class="w-100">
		<view class="flex-1 mx-3 my-2">
			<view class="flex-1 search-box border row-ac">
				<view class="iconfont icon-sousuo ml-3"></view>
				<input type="text" value="" v-model="queryInfo.search" placeholder="搜索课程" class="py-2 px-2 flex-1" @focus="handleFocus"
					@blur="handleBlur" />
				<view class="search-button row font-s-3"  v-if="focusStatus == true" @click="getCurriculumList">搜索</view>
			</view>
		</view>
		<view class="flex-1 mt-2 curriculum-box mx-3">
			<view class="curriculum-item flex-1 border-bottom d-f py-3" v-for="(item, index) in curriculumList"
				:key="index" @click="toCurriculum(item.id)">
				<image :src="item.cover_image" class="curriculum-img" mode=""></image>
				<view class="flex-1 mx-3 mt-1">
					<view class="font-s-4 font-w">{{ item.curriculum_name }}</view>
					<view class="row-ac text-muted font-s-2 mt-1">老师：{{ item.lecturer_name }}</view>
					<view class="row-ac text-muted font-s-2 mt-3">{{ item.create_time }}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		curriculumListUrl
	} from "@/api/index.js"
	export default {
		data() {
			return {
				focusStatus:false,
				queryInfo: {
					search:'',
					category_id: '',
					page: 1,
					page_size: 10
				},
				curriculumList: [],
				curriculumTotal: 0
			}
		},
		onLoad() {
			this.getCurriculumList()
		},
		onReachBottom() {
			this.onReachBottomHandle();
		},
		methods: {
			getCurriculumList() {
				this.$R.get(curriculumListUrl, this.queryInfo).then(res => {
					if (res.code == 200) {
						this.curriculumList = res.data.list
						this.curriculumTotal = res.data.total
					}
				})
			},
			onReachBottomHandle() {
				// 触底事件
				if (this.curriculumTotal != this.curriculumList.length) {
					this.queryInfo.page_size += 10;
					this.getCurriculumList()
				}
			},
			toCurriculum(curriculumId) {
				uni.navigateTo({
					url: '/pages/school/curriculum?curriculumId=' + curriculumId,
				});
			},
			handleFocus() {
				this.focusStatus = true
			},
			handleBlur(){
				this.focusStatus = false
			}
			
		}
	}
</script>

<style lang="scss">
	.curriculum-item {
		.curriculum-img {
			width: 158rpx;
			height: 198rpx;
		}
	}

	.search-box {
		height: 62rpx;
		border-radius: 31rpx;
		.search-button{
			width: 88rpx;
			height: 60rpx;
			border-radius: 0 30rpx 30rpx 0;
			background-color: #000;
			color: #fff;
		}
	}
</style>